const path = require('path')
const ejs = require('ejs')
const express = require(`express`)
const cors = require('cors')
const bodyparse = require('body-parser')
let app = express()
let rooter = require(`./public/rooter/rooter-define`)
let config = require('./public/rooter/config')
let { expressjwt: jwt } = require("express-jwt");
// 对请求头中携带的token字符串进行解析，并且每个请求都必须带token字符串
// app.use(
//   jwt({
//     secret: config.secret,
//     algorithms: ["HS256"],
//   }).unless({ path: ["/api"] })
// );
// 解析请求体中的json格式和键值对格式
// app.use(express.json())
// app.use(express.urlencoded({ extended: false }))
app.use(bodyparse.urlencoded({ extended: false }))
app.use(bodyparse.json())
app.set('view engine', 'ejs')
app.set('views', './views')
// 静态资源目录
app.use(express.static(path.resolve(__dirname + '/public')))

// 以下路由能跨域
app.use(cors())
app.use(rooter)

app.listen(5000, function () {
  console.log("5000端口的监听已开启");
})
